/*
	       File: FileProcessingController.cs
	Create Date: 2007-08-01
	    Version:

	Description:


	 Change log:


*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Workflow;
using System.Workflow.Activities;
using System.Workflow.Runtime;

using GuerillaProgrammer.Components.Logging;
using GuerillaProgrammer.Components.GPThreadPool;
using GuerillaProgrammer.FileProcessor.Settings;

namespace GuerillaProgrammer.FileProcessor
{
    public class FileProcessingController : IWorkItemProcessor 
    {
        #region Private member fields
        private Configuration _Configuration;
        private GPThreadPool _FileProcessorPool;
        #endregion

        #region Constructors and cleanup methods
        private FileProcessingController()
        {
        }
        public FileProcessingController(Configuration configuration)
        {
            _Configuration = configuration;

            int maxThreads = 1;
            int.TryParse(_Configuration.Services.MaxFileProcessorWorkThreads, out maxThreads);

            _FileProcessorPool = new GPThreadPool(maxThreads);
        }
        #endregion

        #region Public interface
        public void ProcessWorkItem(WorkItem workItem)
        {
            FileProcessor processor = new FileProcessor(workItem, _Configuration);
            WaitCallback procStart = new WaitCallback(processor.ProcessWorkItem);
            _FileProcessorPool.QueueItem(procStart);
        }
        #endregion
    }
}
